'use strict';

angular.module('snPaas_om')
	.controller('NewVersionCtrl',['$scope','baseUrl','versionStore','SpSlider',function($scope,baseUrl,versionStore,SpSlider){
		var vm = $scope;
		vm.baseUrl = baseUrl.static;
		vm.versionFile = null;
		vm.upLoading = false;
		vm.uploaded = false;
		vm.uploadError  = false;
		vm.uploadProcess = 0;

		vm.addVersion = function(){
			if(!vm.versionFile){
				SpSlider.slideIn({
	              title: "提示",
	              content: '请选择CF版本文件！',
	              type:'alert'
	            });
	            return;
			}
			vm.upLoading = true;
			versionStore.addVersion({file:vm.versionFile}).then(function(res){
				vm.upLoading = false;
				vm.upLoaded = true;
				SpSlider.slideIn({
	              title: "上传完成",
	              content: '上传CF版本包完成！',
	              type:'noti'
	            });
			},function(res){
				vm.upLoading = false;
				SpSlider.slideIn({
	              title: "服务端异常",
	              content: '上传文件失败！',
	              type:'alert'
	            });

			},function(res){
				vm.uploadProcess = parseInt(res.loaded*100/res.total);
				if(vm.uploadProcess==100){
					vm.upLoading = false;
					vm.uploaded = true;
				}
			});
		};
		
		
	
	}]);

